<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>SelectField Test Suite</title>
    <script type="text/javascript" src="../js/inputex-loader.js"></script>
</head>
<body class="yui-skin-sam">
<h1>
    <script>document.write(document.title)</script>
</h1>

<div id="test"></div>

<script type="text/javascript">
    inputEx.YUI({base:'../lib/yui3/',inputExBase:'../'}).use('node', 'console', 'yuitest', 'selectfield', function(Y) {
        Y.namespace('inputEx.tests')
        Y.inputEx.tests.SelectFieldTests = new Y.Test.Case({
            name: 'Select Field Tests',
            setUp:function() {
                this.data = {}
                Y.get('#test').set('innerHTML', '')
            },
            tearDown:function() {
                delete this.data;
            },

            testLoader:function() {
                Y.Assert.isTrue(typeof(Y.inputEx) !== 'undefined')
                Y.Assert.isTrue(typeof(Y.inputEx.SelectField) !== 'undefined')
            },

            testConstructor:function() {
                var field = new Y.inputEx.SelectField()
                Y.Assert.isNotUndefined(field)
                Y.Assert.isInstanceOf(Y.inputEx.SelectField, field, 'Incorrect type')
                //Y.Assert.isObject(test01.get('boundingBox'))
                //Y.get('#test').contains(test01.get('boundingBox'))
            },
            
            testRendering:function() {
                var container = Y.Node.create('<div id="testRendering"></div>')
                Y.get('#test').appendChild(container)

                var test = new Y.inputEx.SelectField()
                Y.Assert.isNotUndefined(test)
                Y.Assert.isNull(container.query('select'))
                test.render(container)
                Y.Assert.isNotUndefined(container.query('select'))
            },
            testSelectElAttrs:function() {
                var container = Y.Node.create('<div id="testSelectElAttrs"></div>')
                Y.get('#test').appendChild(container)

                //case 1: selectValues only
                var field = new Y.inputEx.SelectField({id:'countryTest',name: 'country',size:2})
                field.render(container)
                var selectEl = container.query('select')
                Y.Assert.isNotUndefined(selectEl)
                Y.Assert.areEqual(field.get('name'), selectEl.get('name'))
                Y.Assert.areEqual(field.get('id') + '-field', selectEl.get('id'))
                Y.Assert.areEqual(field.get('size'), selectEl.get('size')) // default size is 1
            },

            XtestSelectElements:function() {
                var container = Y.Node.create('<div id="testSelectElements"></div>')
                Y.get('#test').appendChild(container)

                //case 1: selectValues only
                var field = new Y.inputEx.SelectField({id:'country',name: 'country', selectValues: ['United States','France']})
                field.render(container)
                var selectEl = container.query('select')
                Y.Assert.isNotUndefined(selectEl)
                //                var optionEls = Y.all('#country-field option')
                Y.log('query: ' + selectEl.queryAll('option'), 'info', 'dev')
                //                Y.Assert.isInstanceOf(Y.NodeList, optionEls)
                //Y.Assert.areEqual(field.get('selectValues').length, selectEl.queryAll('option').length)
            }



        })


        //TODO: Y.Console{width:'600px'} won't work, simplify the following once the console height and width have been fixed
        var console = new Y.Console()
        console.get('contentBox').setStyle('width', (Y.get('body').get('docWidth') * 3 / 4) + 'px')
        console.render()
        console.get('contentBox').query('div .yui-console-bd').setStyle('height', (Y.get('body').get('docHeight') * 4 / 5) + 'px')
        console.on('entry', function(e) {if (e.message.source !== 'TestRunner') { e.preventDefault()} })
        
        Y.Test.Runner.add(Y.inputEx.tests.SelectFieldTests);
        Y.Test.Runner.run();

    })
</script>
</body>

</html>
